function resolution = GetResolution(DarisID,LocalCacheDir,info)
%% GetResolution 
% Retreives the physical dimensions 
% of the dataset image. Assumes isotropic.
% Usage: 
%    >> [~ strlist] = GetResolution('1008.2.18.3.1.1.1',Dir)
%
%  - Michael Eager (michael.eager@monash.edu)

%     Copyright © 2012-2013 Michael Eager <michael.eager@monash.edu> 
%
%     This file is part of Xglom.
% 
%     This is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.

currentFolder = pwd;

if nargin < 1
    disp(['GetResolution assuming local ' ...
          'datasets are stored in directory ''Cache'' ']);
    CacheDir = fullfile(currentFolder,'Cache');
else
    CacheDir = LocalCacheDir
end

if nargin < 2
    if ~isdir(fullfile(CacheDir,DarisID)) && ~exist(fullfile(CacheDir,DarisID,'0001.dcm'),'file')
        info = GetDICOMInfo(DatasetID);
    end
end

if exist('info.PixelDimensions')
   PixelDimension = info.PixelDimensions(1);
   
elseif exist('info.PixelSpacing')
    PixelDimension = info.PixelSpacing(1);
elseif exist('info.SliceThickness')
    PixelDimension = info.SliceThickness;
elseif exist('info.SpacingBetweenSlices')
    PixelDimension = info.SpacingBetweenSlices;
else
  PixelDimension=0.1; %100 micron
end
    
resolution = ones(1,3).*PixelDimension;
